#ifndef _BUS_DETECT_H
#define _BUS_DETECT_H

#include "base_drv/drv_conf.h"
#include HAL_INCLUDE

#define CHASSIS_INDEX 0
#define GIMBAL_INDEX 1
#define SHOOT_INDEX 2

void detect_loop(void);

uint32_t is_motor_online(uint32_t m_id);
void inc_module_rx_lost(uint32_t i);
void reset_module_rx_lost(uint32_t i);

void disable_all_it(void);

void mpu_nx_protect(void);

/*
��ȡ��λ����
READ_BIT(RCC->CSR, Flags) == Flags
Flags: 
RCC_CSR_LPWRRSTF   < Low-Power reset flag 
RCC_CSR_PINRSTF    < PIN reset flag 
RCC_CSR_PORRSTF    < POR/PDR reset flag 
RCC_CSR_SFTRSTF    < Software Reset flag 
RCC_CSR_IWDGRSTF   < Independent Watchdog reset flag 
RCC_CSR_WWDGRSTF   < Window watchdog reset flag 
RCC_CSR_BORRSTF    < BOR reset flag (Brown-out reset,Ƿѹ��λ)

*/
inline uint32_t RCC_FLAG(uint32_t flags){
    return (READ_BIT(RCC->CSR, flags) == flags);
}

//#define IS_POR (RCC_FLAG(RCC_CSR_PORRSTF))
//#define IS_IWDG_RST (RCC_FLAG(RCC_CSR_IWDGRSTF))
#define _DEBUG 1

#if _DEBUG == 1
#define FAULT_HANDLER __BKPT(0xbe);
#else
#define FAULT_HANDLER __set_FAULTMASK(1);NVIC_SystemReset();
#endif

#endif

